package com.wusw.zoomimageproject;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.wusw.zoomimageproject.widget.ZoomImageView;


public class MainActivity extends Activity {
private ViewPager viewPager;
    private int[] mImgs=new int[]{R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d};
    private ImageView[] mImageViews=new ImageView[mImgs.length];
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_viewpage_main);
        viewPager=(ViewPager)findViewById(R.id.viewPage);
        viewPager.setAdapter(new PagerAdapter() {
            @Override
            public int getCount() {
                return mImageViews.length;
            }

            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view==object;
            }

            @Override
            public Object instantiateItem(ViewGroup container, int position) {
                ZoomImageView imageView=new ZoomImageView(MainActivity.this);
                imageView.setImageResource(mImgs[position]);
                mImageViews[position]=imageView;
                container.addView(imageView);
                return imageView;
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                container.removeView(mImageViews[position]);
            }
        });
    }


}
